<?php
namespace Admin\Controller;
use Admin\Controller\AdminController;
use Think\Page;

class ResponseController extends AdminController {
	
		//关键字回复
		public function keywords(){
			$list = M('keyword')->where("id <> 10001 AND id <> 20002")->select();
			
			$this->assign('list',$list);
			$this->display();
			
		}
		
		//图片回复
		public function pic(){
			 $list = M('keyword')->where("`id`=10001")->select();
			 
			
			$this->assign('list',$list);
			$this->display();
		}
		//关注自动回复
		public function attention(){
			$list = M('keyword')->where("`id`=20002")->select();
			
			$this->assign('list',$list);
			$this->display();
		}
		//添加自动回复
		public function addkeyword(){
			if(IS_POST){
				/*var_dump($_POST);die;
				if(empty($_POST['keyword']) && $_POST['id'] != 10001 && $_POST['id'] != 20002){
					$this->error('填写内容不能为空');
				}
				if(empty($_POST['type'])){
					$this->error('类型不能为空');
				}
				if($_POST['type'] == 'pic_text'){
					if(empty($_POST['title']) || empty($_POST['description']) || empty($_POST['picurl']) || empty($_POST['content'])){
						$this->error('填写内容不能为空');
					}
				}else{
					if(empty($_POST['content'])){
						$this->error('填写内容不能为空');
					}
				}*/
				$_POST['status'] = 0;
				if(empty($_POST['id'])){
					$re = M('Keyword')->add($_POST);
				}else{
					$re = M('Keyword')->where("`id`={$_POST['id']}")->save($_POST);
				}
				
				if($re){
					if($_POST['id'] == 10001){
						$this->success('操作成功',U('Response/pic'));
					}else if($_POST['id'] = 20002){
						$this->success('操作成功',U('Response/attention'));
					}else{
						$this->success('操作成功',U('Response/keywords'));
					}
				}else{
					$this->error('添加失败');
				}
			}else{
				$id = I('id');
				if(!empty($id)){
					$list = M('Keyword')->where("`id`={$id}")->find();
					$this->assign('list',$list);
				}
				$this->display();
			}
			
		}
		
		//删除关键字回复
		public function del(){
			$id=I('id');
			if(empty($id)){
				$this->error('异常访问');
			}
			$re = M('Keyword')->where("`id`={$id}")->delete();
			if($re){
				$this->success("删除成功",U('Response/keywords'));
			}else{
				$this->error('删除失败');
			}
		}
}